<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('openid', 100)->unique()->comment('微信openid');
            $table->string('unionid', 100)->nullable()->comment('微信unionid');
            $table->string('nickname', 50)->nullable()->comment('用户昵称');
            $table->string('password')->nullable()->comment('密码（管理员登录用）');
            $table->string('avatar')->nullable()->comment('头像URL');
            $table->string('phone', 20)->nullable()->comment('手机号');
            $table->tinyInteger('gender')->default(0)->comment('性别：0-未知，1-男，2-女');
            $table->string('city', 50)->nullable()->comment('城市');
            $table->string('province', 50)->nullable()->comment('省份');
            $table->string('country', 50)->nullable()->comment('国家');
            $table->string('language', 10)->default('zh_CN')->comment('语言');
            $table->timestamp('last_login_at')->nullable()->comment('最后登录时间');
            $table->boolean('is_active')->default(true)->comment('是否激活');
            $table->timestamps();
            
            $table->index('openid');
            $table->index('unionid');
            $table->index('phone');
            $table->index('last_login_at');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('users');
    }
};
